package com.hq.ims.data.vo;

import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.AppFile;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 蒋柏平
 *
 * @since 20240920
 */
@Mapper
public interface AppFileMapstruct {

    AppFileMapstruct INSTANCE = Mappers.getMapper(AppFileMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    AppFileVo toAppFileVo(AppFile source);

    default List<AppFileVo> toAppFileVoList(List<AppFile> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toAppFileVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class AppFileVo extends AppFile {

    }

    @Data
    class AppFileTree extends AppFile {

        private List<AppFileTree> childrenList;

    }

    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

    }

    //-------------------------------- 以下为自定义类[其它] --------------------------------

    @Data
    class FileVo {

        @NotBlank(message = "文件ID不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "文件ID")
        private String fileId;

        @NotBlank(message = "文件名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "文件名称")
        private String fileName;

        @NotBlank(message = "文件预览URL不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "文件访问URL(不能直接在浏览器上直接打开的则跟下载地址一样)")
        private String filePreviewUrl;

        @NotBlank(message = "文件预览URL不能为空", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "文件访问URL")
        private String fileDownloadUrl;

        @NotNull
        @ApiModelProperty(value = "文件大小")
        private Long fileSize;

        @ApiModelProperty(value = "文件后缀")
        private String fileSuffix;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
